#!/var/bin/bash
# -*- coding: utf-8 -*-
import time
import numpy as np
import threading
import tracemalloc

tracemalloc.start(25)

from data_manager.matplotlib_draw_manager import MatplotlibDrawManager


def print_memory_used():
    snapshot = tracemalloc.take_snapshot()
    while True:
        try:
            snapshot1 = tracemalloc.take_snapshot()
            top_stats = snapshot1.compare_to(snapshot, 'lineno')
            # logger.warning("[ Top 20 differences ]")
            for stat in top_stats[:20]:
                if stat.size_diff < 0:
                    continue
                # logger.warning(stat)
                print(stat)
            print("---------------------------")
            # snapshot = tracemalloc.take_snapshot()

        except Exception as e:
            print(e)
            pass

        time.sleep(5)


if __name__ == '__main__':
    # threading.Thread(target=print_memory_used).start()
    times = 100
    time_int = int(time.time())
    x = np.array([time_int + i * 45 for i in range(times)])
    y = np.array([[i + 1, i + 200, i + 300, i + 60] for i in range(times)])
    label = ("<0.5mm", "0.5-1mm", "1-2mm", ">2mm")
    while True:
        matplotlib_draw = MatplotlibDrawManager()
        matplotlib_draw.creat_figure(figsize=(12.8, 9.6))
        matplotlib_draw.plot_draw(x, y, label=label)

        matplotlib_draw.pie_generation("g", "jh")
        matplotlib_draw.close_figure()

        time.sleep(0.01)
